/*###################################################################*
#
# MP (Mitchell Pell) Base - CrossPlatform Base Utilities.
# Copyright (C) 2014  Mitchell Pell
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
####################################################################*/
#ifndef GL_TCP_DATA_H
#define GL_TCP_DATA_H

#include "NetworkDefines.h"
#include "TcpError.h"
#include "../../../Base/Event.h"
#include <string>
using mp_base::interfaces::Event;
using std::string;

namespace mpgl_engine{ namespace application{ namespace net {

	enum class TcpDataState
	{
		EMPTY	= 0x00,
		READY	= 0x01,
		UNKNOWN = 0xFF
	};

	/*!----------------------------------------------------------------
	*	@class		TcpData
	*	@brief		This class represents a TCP Data handler. It
	*				inherits from Event and is used to send and receive
	*				data.
	*
	*	@author		Mitchell Pell
	*	@date		01/04/2014
	*	@version	1.0
	*
	*	@revisions	Revision History:
	*
	*					- Version 1.0 01/04/2014
	*						-# Initial Make
	*
	-----------------------------------------------------------------*/
	class TcpData : public Event
	{
	public:
		/*! @brief Default Constructor. */
		TcpData(ushort bufferMax = NetworkDefines::TCP_DATA_MAX);

		/*! @brief Destructor. */
		virtual ~TcpData(){}

		/*! 
		@brief	Access and modify the data stream directly.
		@note	An external mutex lock is required if the network
				is operating on a separate thread.
		*/
		char* AccessDataBuffer() { return m_dataBuffer; }
		/*!  */
		const char* GetDataBuffer() const { return m_dataBuffer; }
		/*!  */
		void SetDataBuffer(char* buffer){ m_dataBuffer = buffer; }
		/*!  */
		const ushort GetBufferLength() const { return m_bufferLength; }
		/*!  */
		const ushort GetBufferIndex() const { return m_bufferIndex; }

	private:
		ushort					m_bufferIndex;
		ushort					m_bufferLength;
		char*					m_dataBuffer;
		volatile TcpDataState	m_state;
	};
}}}

#endif